프롬프트 공학의 기초
프롬프트 공학 (PE) 대규모 언어 모델(LLM)이 고품질이고 일관된 결과를 내도록 안내하기 위해 텍스트 입력을 설계하고 최적화하는 과정이다.
1. 인터페이스 정의
무엇인가: 이는 생성형 AI의 주요 '프로그래밍' 인터페이스로 작용한다.
왜냐하면: 이것은 원시적이며 예측 불가능한 텍스트 예측에서 의도적이고 구조적인 명령 실행으로 상호작용을 전환한다.
2. 모델 기반
- 기본 LLMs: 거대한 데이터셋 속 통계적 관계에 기반하여 다음 토큰을 예측하도록 단순히 훈련되었으며, 확률 $P(w_t | w_1, w_2, ..., w_{t-1})$를 최대화한다.
- 지시 조정된 LLMs: 사람의 피드백을 활용한 강화 학습(Reinforcement Learning with Human Feedback, RLHF)을 통해 특정 지시를 명확히 따르고 도움이 되는 보조자처럼 행동하도록 세밀하게 조정되었다.
3. 성공적인 프롬프트의 구성 요소
어떻게: 강력한 프롬프트는 일반적으로 다음을 포함한다:
- 지시사항: 필요한 특정 작업.
- 주요 콘텐츠: 처리할 대상 데이터.
- 보조 콘텐츠: 파라미터, 형식 또는 제약조건 (확률성과 환각 현상 해결을 위해).
토크나이제이션의 진실
모델은 단어를 읽지 않는다. 그들은 토큰들—통계적 확률 계산에 사용되는 텍스트 시퀀스의 더 작은 단위.
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
What is the primary difference between a Base LLM and an Instruction-Tuned LLM?
Question 2
Why is the use of delimiters (like triple backticks or hashes) considered a best practice in prompt engineering?
Challenge: Tutor AI Constraints
Refining prompts for educational safety.
You are building a tutor-style AI for a startup. The model is currently giving away answers too quickly and sometimes making up facts when it doesn't know the answer.
Task 1
Implement "Chain-of-thought" prompting in the system message to prevent the AI from giving away answers immediately.
Solution:
Instruct the model to:
Instruct the model to:
"Work through the problem step-by-step before providing the final answer. Do not reveal the final answer until the student has attempted the steps."Task 2
Apply an "out" to prevent fabrications (hallucinations) when the AI doesn't know the answer.
Solution:
Add the explicit instruction:
Add the explicit instruction:
"If you do not know the answer based on the provided text or standard curriculum, state clearly that you do not know."